package com.zznode.redsun.commons.dto;

import java.util.Date;

import org.springframework.util.StringUtils;

import com.zznode.csp.domain.commons.util.MapCreaterBuilder;

public class QueryParameter {

	private String code;
	private String name;
	private Date createStart;
	private Date createEnd;

	public String buildSql(String querySql, MapCreaterBuilder parameters, String prefix) {
		prefix = StringUtils.hasText(prefix) ? prefix : "";
		StringBuilder builder = new StringBuilder(querySql);
		if (StringUtils.hasText(code)) {
			builder.append(" and " + prefix + "code like :code");
			parameters.put("code", "%" + code + "%");
		}
		if (StringUtils.hasText(name)) {
			builder.append(" and " + prefix + "name like :name");
			parameters.put("name", "%" + name + "%");
		}
		if (null != createStart) {
			builder.append(" and " + prefix + "create_date >= :createStart");
			parameters.put("createStart", createStart);
		}
		if (null != createEnd) {
			builder.append(" and " + prefix + "create_date >= :createEnd");
			parameters.put("createEnd", createEnd);
		}
		return builder.toString();
	}

	public String buildSql(String querySql, MapCreaterBuilder parameters) {
		return buildSql(querySql, parameters, null);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getCreateStart() {
		return createStart;
	}

	public void setCreateStart(Date createStart) {
		this.createStart = createStart;
	}

	public Date getCreateEnd() {
		return createEnd;
	}

	public void setCreateEnd(Date createEnd) {
		this.createEnd = createEnd;
	}

}
